//
//  Meeting_DetailHeaderView.m
//  HuaRun2
//
//  Created by admin on 2017/9/9.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "Meeting_DetailHeaderView.h"
#import "LineView.h"

@interface Meeting_DetailHeaderView ()

@property (nonatomic, strong) UIView * backView;

//线1
@property (nonatomic, strong) LineView * line1;
@end

@implementation Meeting_DetailHeaderView

#pragma mark - life cycle

- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    self.backgroundColor = RGBA(249, 249, 249, 1);
    
    [self addSubview:self.backView];
    [self addSubview:self.nameLab];
    
    [self addSubview:self.noteView];
    
    [self addSubview:self.roleView];
    [self addSubview:self.meetingView];
    
    [self addSubview:self.line1];
    
}

- (void)layoutInit {
    weakself(ws);
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws).offset(kMargin10);
        make.right.mas_equalTo(ws).offset(-kMargin10);
        make.top.mas_equalTo(ws).offset(0);
        make.bottom.mas_equalTo(ws);
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView).offset(kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin15);
        make.right.mas_equalTo(ws.noteView.mas_left).offset(-kMargin10 );
    }];
    
    [self.noteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(ws.backView);
        make.top.mas_equalTo(ws.nameLab);
        make.size.mas_equalTo(CGSizeMake(80, 20));
    }];
    
    [self.meetingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(ws.backView);
        make.bottom.mas_equalTo(ws.backView.mas_bottom).offset(-kMargin15);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    
    [self.roleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(ws.meetingView.mas_left).offset(-kMargin15);;
        make.size.bottom.mas_equalTo(ws.meetingView);
    }];

    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.mas_equalTo(ws.roleView);
        make.width.mas_equalTo(1);
        make.left.mas_equalTo(ws.roleView.mas_right).offset(kMargin15/ 2);
    }];
    
}
#pragma mark - getter

- (UIView *)backView {
    if (!_backView) {
        self.backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kFontSize15;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _nameLab.text = @"name";
    }
    return _nameLab;
}
- (UIView *)noteView {
    if (!_noteView) {
        self.noteView = [self makeCommonLabelWithText:@"查看备注" imageName:@"最近查看"];
    }
    return _noteView;
}

- (UIView *)roleView {
    if (!_roleView) {
        self.roleView = [self makeCommonLabel2WithText:@"角色" imageName:@"联系人001"];
    }
    return _roleView;
}
- (UIView *)meetingView {
    if (!_meetingView) {
        self.meetingView = [self makeCommonLabel2WithText:@"会议" imageName:@"会议001"];
    }
    return _meetingView;
}

- (LineView *)line1 {
    if (!_line1) {
        self.line1 = [LineView new];
    }
    return _line1;
}

- (UIView *)makeCommonLabelWithText:(NSString *)text
                          imageName:(NSString *)imageName{
    UIView * view = [[UIView alloc] init];
    view.backgroundColor = kRandomColor;
    view.frame = CGRectMake(0, 0, 80, 20);
    
    UIImageView * iconView = [UIImageView new];
    iconView.image = [UIImage imageNamed:imageName];
    iconView.frame = CGRectMake(0, 2.5, 15, 15);
    [view addSubview:iconView];
    
    UILabel * companyLab = [UILabel new];
    companyLab.textAlignment = NSTextAlignmentLeft;
    companyLab.frame = CGRectMake(20, 0, 60, 20);
    companyLab.font = kGeneralFontSize;
    companyLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    companyLab.text = text;
    [view addSubview:companyLab];
    
    return view;
}

- (UIView *)makeCommonLabel2WithText:(NSString *)text
                           imageName:(NSString *)imageName{
    UIView * view = [[UIView alloc] init];
    view.backgroundColor = kRandomColor;
    view.frame = CGRectMake(0, 0, 80, 30);
    [UIColor whiteColor];
    UIImageView * iconView = [UIImageView new];
    iconView.image = [UIImage imageNamed:imageName];
    iconView.frame = CGRectMake(0, 5, 20, 20);
    [view addSubview:iconView];
    
    UILabel * companyLab = [UILabel new];
    companyLab.textAlignment = NSTextAlignmentLeft;
    companyLab.frame = CGRectMake(25, 5, 60, 20);
    companyLab.font = kGeneralFontSize;
    companyLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    companyLab.text = text;
    companyLab.tag = 200;
    [view addSubview:companyLab];
    
    return view;
}
- (void)resetContactNum:(NSString *)num {
    
    [self commonReSetNum:num view:self.roleView];
}

- (void)commonReSetNum:(NSString *)num view:(UIView *)view {
    UILabel * label = [view viewWithTag:200];
    label.text = [NSString stringWithFormat:@"%@(%@)", label.text,
                  num];
}
- (void)resetMeetingNum:(NSString *)num {
    [self commonReSetNum:num view:self.meetingView];
}

@end
